<?php

namespace app\admin\model;

use think\Model;
use think\model\concern\SoftDelete;

class VideoCategory extends Model
{
    use SoftDelete;

    protected $autoWriteTimestamp = true;

    protected $pk = 'category_id';

    public static function getList()
    {
        $where = [];
        $limit = input('get.limit');
        $page = input('get.page');
        if ($search = input('get.category_title')) $where[] = ['category_title', 'like', "%" . $search . "%"];
        $list = self::order('category_id', 'desc')
            ->where($where)
            ->paginate($limit);
        foreach ($list as $k => $v) {
            $list[$k]['category_remark'] = $v['category_remark'] ?: '-';
        }
        return ['code' => 0, 'data' => $list->items(), 'extend' => ['count' => $list->total(), 'limit' => $limit, 'page' => $page]];
    }

    public static function checkExist($categoryId, $categoryTitle)
    {
        return self::where('category_id', '<>', $categoryId)
            ->where('category_title', $categoryTitle)
            ->find();
    }

    public static function getCategoryAll()
    {
        return self::order('category_sort desc,category_id desc')
            ->field(['category_id', 'category_title'])
            ->where('category_status', '=', 1)
            ->select()
            ->toArray();
    }
}